﻿using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;

namespace BrainTechLLC.WPF
{
    public class OppositeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return null;

            Type t = value.GetType();

            if (t == typeof(bool))
            {
                return !(bool)value;
            }
            else if (t == typeof(Visibility))
            {
                Visibility v = (Visibility)value;
                return v == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return null;

            Type t = value.GetType();

            if (t == typeof(bool))
            {
                return !(bool)value;
            }
            else if (t == typeof(Visibility))
            {
                Visibility v = (Visibility)value;
                return v == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
            }
            else
            {
                throw new Exception("Cannot convert back");
            }
        }
    }

}
